<?php
	namespace Api\Controller;
	use Think\Controller;
	header("Content-Type:text/html;charset=utf-8");
	class AttestationController extends Controller
	{
		/*
		 * 个人/企业认证
		 *  
		 */
		public function attestationUser($uid=null, $token=null, $type=null)
		{
// 			if ($this->checkedToken($uid, $token)) 
// 			{
				$where["uid"] = $uid;
				$userInfo = M("User") -> field("uid,nickname,type") -> where($where) -> find();
				var_dump($userInfo);
				if ($userInfo["type"] == 0) 
				{
					//个人认证
					$img = base64_decode($_REQUEST['attimg']);
					$oldname = $_REQUEST['oldname'];
					$index = strrpos($oldname, ".");//对文件名进行“.”截取
					$ext = substr($oldname, $index);//获得文件的扩展名
					$newname = md5(time() . rand(0, 9999)).$ext;
					$result = file_put_contents('./Public/Uploads/Headimg/'.$newname, $img);
					$data["headimg"] = "http://192.168.1.119/loveshow/Public/Uploads/Headimg/".$newname;
				}
				else
				{
					//企业认证
				}
// 			}
// 			else
// 			{
// 				$array1['result'] = 10310;
// 				$array1['message'] = "获取视频失败";
// 				echo json_encode($array1, JSON_UNESCAPED_SLASHES);
// 				exit;
// 			}
		}
		
		/*
		 *验证token的方法
		*
		*/
		protected function checkedToken($uid = null,$token = null)
		{
			if ($uid==null || $token==null)
			{
				return false;
			}
			else
			{
				$where["uid"] = $uid;
				$tokeninfo = M("User") -> where($where) -> getField("token");
				if ($token == $tokeninfo)
				{
					return true;
				}
				else
				{
					return false;
				}
			}
		}
	}